package com.yuneec.droneservice.command;

import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

/**
 * Created by gjw on 2017/3/27.
 */

public class BindCamera extends BaseCommand {

    public BindCamera(String ssid, String password) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_BIND_CAMERA);
        try {
            byte[] ssidBytes = ssid.getBytes("utf-8");
            byte[] passwordBytes = password.getBytes("utf-8");
            data = new byte[4 + ssidBytes.length + passwordBytes.length];
            ByteUtils.shortToByteArray(data, 0, (short) ssidBytes.length, IS_BIGENDIAN);
            System.arraycopy(ssidBytes, 0, data, 2, ssidBytes.length);
            ByteUtils.shortToByteArray(data, 2 + ssidBytes.length, (short) passwordBytes.length, IS_BIGENDIAN);
            System.arraycopy(passwordBytes, 0, data, 4 + ssidBytes.length, passwordBytes.length);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public IResponse toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        return new IResponse(ids(), code);
    }
}
